package com.shixulin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shixulin.domain.ResponseResult;
import com.shixulin.entity.MyExam;
import com.shixulin.entity.UserExam;
import com.shixulin.mapper.UserExamMapper;
import com.shixulin.service.UserExamService;
import org.mockito.internal.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (UserExam)表服务实现类
 *
 * @author makejava
 * @since 2023-12-17 17:00:19
 */
@Service("userExamService")
public class UserExamServiceImpl extends ServiceImpl<UserExamMapper, UserExam> implements UserExamService {

    @Autowired
    private UserExamMapper userExamMapper;
    @Override
    public ResponseResult isStatus(int userId,int paperId) {
        List<UserExam> userExams = userExamMapper.isStatus(userId,paperId);

        if (userExams!=null&&!userExams.isEmpty()){
            UserExam userExam1 = userExamMapper.getMaxStatus(userId,paperId);
            int status = userExam1.getExamStatus();
            return new ResponseResult(300,"成功",userExam1);
        }else {
            return new ResponseResult(500,"失败");
        }
    }

    @Override
    public ResponseResult saveUserExam(UserExam userExam) {
        int insert  = this.baseMapper.insert(userExam);
        if (insert>0){
            return new ResponseResult(300,"成功");
        }else {
            return new ResponseResult(500, "失败");
        }
    }


}